package test;

import repast.simphony.parameter.Parameters;

import defectsim.SimulationEnvironment;
import defectsim.agents.DefectAgent;
import defectsim.agents.DefectFactory;
import defectsim.agents.Dislocation;
import defectsim.agents.EdgeDislocation;
import defectsim.agents.DefectFactory.DefectType;
import defectsim.material.SlipSystem;

public class DislocationSourceTester4 extends DefectAgent{

	private Dislocation tester = null;

	private SimulationEnvironment env = SimulationEnvironment.getInstance();
	private double gridScale;
	private boolean multiplied = false;

	@Override
	public void percept() {
	}

	@Override
	public void mentalUpdate() {
	}

	@Override
	public void act() {
		if (!multiplied) {
			this.multiply(1000);
			multiplied = true;
		}
		
	}

	public DislocationSourceTester4(){
		Parameters p = env.getParameters();
		int gridSize = (Integer)p.getValue("gridsize");		
		double boxLength = (Double)p.getValue("spacelength");
		this.gridScale = gridSize / boxLength;
		multiplied = false;
	}

	private void multiply(int noOfDislocations){
		int s = 0;
		SlipSystem[] slipsys = env.getMaterial().getSlipSystems();
		EdgeDislocation dislocation = (EdgeDislocation) DefectFactory.createDefect(DefectType.EdgeDislocation);
		dislocation.setSlipSystem(slipsys[s]);
		dislocation.setUnitBurgersVector(1);
		dislocation.setX(5.0);
		dislocation.setY(5.0);
		dislocation.setLocationGridX((int)(3 * gridScale));
		dislocation.setLocationGridY((int)(7 * gridScale));
		System.out.println("Nucleated1");
		env.nucleate(dislocation);
		EdgeDislocation dislocation1 = (EdgeDislocation) DefectFactory.createDefect(DefectType.EdgeDislocation);
		dislocation1.setSlipSystem(slipsys[s]);
		dislocation1.setUnitBurgersVector(-1);
		dislocation1.setX(5.5);
		dislocation1.setY(5.05);
		dislocation1.setLocationGridX((int)(6 * gridScale));
		dislocation1.setLocationGridY((int)(4 * gridScale));
		env.nucleate(dislocation1);
		tester = dislocation1;
	}

	public Dislocation getDislocationTester(){
		return tester;
	}

}
